CC = gcc
CFLAGS = -Wall -Wextra
CPPFLAGS = -I$(HEADERS_DIR)

BASE_DIR = ./
HEADERS_DIR = $(BASE_DIR)headers/
SOURCES_DIR = $(BASE_DIR)src/
OBJECTS_DIR = $(BASE_DIR)objs/

HEADERS = header.h
SOURCES = main.c print.c
OBJECTS = main.o print.o

HEADERS_LIST = $(addprefix $(HEADERS_DIR), $(HEADERS))
SOURCES_LIST = $(addprefix $(SOURCES_DIR), $(SOURCES))
OBJECTS_LIST = $(addprefix $(OBJECTS_DIR), $(OBJECTS))

ifdef VERBOSE
	CPPFLAGS += -DVERBOSE
endif

.PHONY: all clean

all: $(OBJECTS_LIST)
	$(CC) $(CFLAGS) $^ -o program
	
$(OBJECTS_DIR)%.o: $(SOURCES_DIR)%.c $(HEADERS_LIST)
	$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
	
clean:
	rm program* $(OBJECTS_LIST)
